package TableAndSQL

import org.apache.flink.api.scala.ExecutionEnvironment
import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
import org.apache.flink.table.api.EnvironmentSettings
import org.apache.flink.table.api.scala.{BatchTableEnvironment, StreamTableEnvironment}

object TabelAPITest {
  def main(args: Array[String]): Unit = {
    /**
     * 环境的创建
     */
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    env.setParallelism(1)

    //创建Table环境
    val tableEnv = StreamTableEnvironment.create(env)

    //基于老版本planner的流处理
    val settings = EnvironmentSettings.newInstance()
      .useOldPlanner() //老版本
      .inStreamingMode() //流处理
      .build()
    val oldStreamTableEnv = StreamTableEnvironment.create(env, settings)

    //基于老版本的批处理,老版本不是批流合一的，需要先创建一个批处理
    val batchEnv = ExecutionEnvironment.getExecutionEnvironment
    val oldBatchTableEnv = BatchTableEnvironment.create(batchEnv)

    //基于blink版本的流式处理
    val blinkStreamSettings = EnvironmentSettings.newInstance()
      .useBlinkPlanner()
      .inStreamingMode()
      .build()
    val blinkStreamTableEnv = StreamTableEnvironment.create(env, blinkStreamSettings)

    //基于blink版本的批处理
    val blinkBatchSettings = EnvironmentSettings.newInstance()
      .useBlinkPlanner()
      .inBatchMode()
      .build()
    val blinkBatchTableEnv = StreamTableEnvironment.create(env, blinkBatchSettings)
  }
}
